home *** CD-ROM | disk | FTP | other *** search
- Path: news.gate.net!pslfl2-48
- From: bhutto@gate.net (William Hutto)
- Newsgroups: comp.lang.c
- Subject: Re: Printing to LPT1 Printer from within program
- Followup-To: comp.lang.c
- Date: 25 Jan 1996 16:07:56 GMT
- Organization: CyberGate, Inc.
- Message-ID: <4e89ss$1mns@news.gate.net>
- References: <4e5ee9$m28_001@pr.mcs.net>
- NNTP-Posting-Host: pslfl2-48.gate.net
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <4e5ee9$m28_001@pr.mcs.net>,
- mdp@mika-sys.com (Michael D. Perry) spake:
- ;I have just started taking a C programming class and am using Borland
- ;C++ v4.0 at home. Both my teacher and I are stumped as to how to
- ;print to a LPT (Line Printer) device from within the program.
- ;
- ;I have read the FAQ and there are some references to this but not
- ;enough that I can quite figure it out. As near as I can figure you
- ;can use iostreams or fprintf() with the later appearing to be the
- ;simpler of the two. With that, from what I have seen, one uses a
- ;filename of stdprn but I get an error message when compiling. My
- ;guess is that there is a header file or a definition/declaration
- ;statement that needs to be referenced.
- ;
- ;In Pascal the Function LPrint() does this job quite nicely but I can
- ;find no suitable similar function in my reference manuals. Can anyone
- ;help with the appropriate function(s) and perhaps some examples of
- ;them in source code?
- ;
- ;I have looked at lots of materials on the Internet, quite a few books,
- ;and hours in the on-line help and manuals for Borland C++ without
- ;finding anything much about this. So either I am incredibly stupid
- ;because the answer is so obvious that no one writes about it or it is
- ;a little more obscure and someone maybe should write it into an FAQ?
- ;
- ;Thanks in advance;
- ;
- ;Mike
-
- You didn't play pro football did you? Anyway, with DOS, you are given
- an open file to the standard printer at the start of your program. You can
- usually access this file in C with the predefined 'stdprn' FILE * in
- <stdio.h>, used thusly:
-
- fprintf(stdprn,"Send this line to the standard printer.\n");
-
- If for some reason 'LPT1' were not the stdprn, you could still open it like a
- file in DOS:
-
- FILE *lpt1;
-
- if((lpt1=fopen("LPT1","w"))==NULL) {
- /*error*/
- }
- fprintf(lpt1,"Send this line to LPT1.\n");
-
- or you can reopen stdprn when it's not the printer you want:
-
- if(!freopen("LPT2","w",stdprn)) {
- /*error*/
- }
- fprintf(stdprn,"This line definitely goes to LPT2.\n");
-
- or even redirect stdout:
-
- if(!freopen("LPT1","w",stdout)) {
- /*error*/
- }
- printf("This line goes to LPT1.\n");
-
- if(!freopen("CON","w",stdout)) {
- /*error*/
- }
- printf("This line goes to screen.\n");
-
-
- Regards,
- Bill
-
- William Hutto
- bhutto@gate.net
- N4YMN
-
- "Whatcha got on?...Your mind?"
-